/**
 * 文件: SearchParameter.java
 * 项目: DFlow
 * 版权所有者:佛山市顺德区北航工业设计有限公司
 * 
 */
package common.bean;

import org.apache.commons.beanutils.PropertyUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SearchParameter implements Serializable {

	private boolean pagination = false;
	
	private int pageIdx = 1;
	
	private int pageSize = 20;
	
	private Map<String,Object> mapParam = new HashMap<String,Object>();
	
	private List<Object> objParam = new ArrayList<Object>();

	public boolean isPagination() {
		return pagination;
	}

	public void setPagination(boolean pagination) {
		this.pagination = pagination;
	}

	public int getPageIdx() {
		return pageIdx;
	}

	public void setPageIdx(int pageIdx) {
		this.pageIdx = pageIdx;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public Map<String, Object> getMapParam() {
		return mapParam;
	}

	public void setMapParam(Map<String, Object> mapParam) {
		this.mapParam = mapParam;
	}

	public List<Object> getObjParam() {
		return objParam;
	}

	public void setObjParam(List<Object> objParam) {
		this.objParam = objParam;
	}

	public void addParam(String paramName, Object paramValue){
		this.mapParam.put(paramName, paramValue);
	}
	
	public void addObjectParam(Object obj){
		this.objParam.add(obj);
	}
	
	public Object getParam(String paramName){
		Object value = null;
		
		value = this.mapParam.get(paramName);
		if(value == null){
			for(Object obj: this.objParam){
				try{
					if(PropertyUtils.getPropertyDescriptor(obj, paramName) != null){
						value = PropertyUtils.getProperty(obj, paramName);
						if(value != null){
							break;
						}
					}
				}catch(Throwable e){
				}
			}
		}
		return value;

	}
}
